{% extends 'SifastProjectBundle:CRUD:base_edit.html.twig' %}
{% block form %}

<script type="text/javascript" src="/js/jquery.smartWizard-2.0.min.js"></script>
<script src="/js/jquery.ui.core.js"></script>
<script src="/js/jquery.ui.widget.js"></script>

<link rel="stylesheet" href="/css/jquery.ui.all.css">
<script type="text/javascript" src="/js/jquery.ui.accordion.js"></script>
<link href="/css/smart_wizard.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
    $(document).ready(function(){
        // Smart Wizard     	
                $('#wizard').smartWizard({transitionEffect:'slideleft',onLeaveStep:leaveAStepCallback,onFinish:onFinishCallback,enableFinishButton:true});

      function leaveAStepCallback(obj){
        var step_num= obj.attr('rel');
        return validateSteps(step_num);
      }
     
      function onFinishCallback(){
       if(validateAllSteps()){
        $('form').submit();
       }
      }
                });
	   
    function validateAllSteps(){
       var isStepValid = true;
       
       if(validateStep1() == false){
         isStepValid = false;
         $('#wizard').smartWizard('setError',{stepnum:1,iserror:true});         
       }else{
         $('#wizard').smartWizard('setError',{stepnum:1,iserror:false});
       }
       
      
       
       if(!isStepValid){
          $('#wizard').smartWizard('showMessage','Please correct the errors in the steps and continue');
       }
              
       return isStepValid;
    } 	
		
		
                function validateSteps(step){
                  var isStepValid = true;
      // validate step 1
      if(step == 1){
        if(true == false ){
          isStepValid = false; 
          $('#wizard').smartWizard('showMessage','Please correct the errors in step'+step+ ' and click next.');
          $('#wizard').smartWizard('setError',{stepnum:step,iserror:true});         
        }else{
          $('#wizard').smartWizard('setError',{stepnum:step,iserror:false});
        }
      }
      
      // validate step3
     
      
      return isStepValid;
    }
		
                function validateStep1(){
       var isValid = true; 
       // Validate Username
       var un = $('input[id$="_matricule"]').val();
       if(!un && un.length <= 0){
         isValid = false;
         $('#msg_matricule').html('Please fill matricule').show();
       }else{
         $('#msg_matricule').html('').hide();
       }
       
       // validate password
      
       
       // validate confirm password
     
       
       // validate password match
      
       return isValid;
    }
    
  //  function validateStep3(){
    //  var isValid = true;    
      //validate email  email
     // var email = $('#email').val();
      // if(email && email.length > 0){
        // if(!isValidEmailAddress(email)){
         //  isValid = false;
           //$('#msg_email').html('Email is invalid').show();           
         //}else{
          //$('#msg_email').html('').hide();
         //}
       //}else{
        // isValid = false;
        // $('#msg_email').html('Please enter email').show();
       //}       
     // return isValid;
    //}
    
    // Email Validation
    function isValidEmailAddress(emailAddress) {
      var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
      return pattern.test(emailAddress);
    } 
		
		
    </script>
 {% set url = admin.id(object) ? 'edit' : 'create' %}

    {% if not admin.hasRoute(url)%}
    <div>
            {{ "form_not_available"|trans({}, "SonataAdminBundle") }}
        </div>

    {% else %}


        <div id="systemUser" class="box">
            <div class="head">
                <h1 id="UserHeading">Add User</h1>
            </div>
            <div class="inner">

                <form id="form_user" action="{{ admin.generateUrl(url, {'id': admin.id(object), 'uniqid': admin.uniqid, 'subclass': app.request.get('subclass')}) }}" {{ form_enctype(form) }} method="POST" method="POST">
                    <input type='hidden' name="issubmit" value="1">
                    <!-- Tabs -->
                    <div id="wizard" class="swMain">
                        <ul>
                            <li><a href="#step-1">
                                    <label class="stepNumber">1</label>
                                    <span class="stepDesc">
                                        Informations<br />Personnelles<br/>
                                        <!--<small>Fill your account details</small>-->
                                    </span>
                                </a></li>
                            <li><a href="#step-2">
                                    <label class="stepNumber">2</label>
                                    <span class="stepDesc">
                                        Informations<br />Professionelles<br/>
                                        <!--<small>Fill your profile details</small>-->
                                    </span>
                                </a></li>
                            <li><a href="#step-3">
                                    <label class="stepNumber">3</label>
                                    <span class="stepDesc">
                                        Rémunerations<br />Théoriques<br/>
                                        <!--<small>Fill your profile details</small>-->
                                    </span>
                                </a></li>

                        </ul>
                            {% set compteur = 1 %}
                            {% set j = 0 %}
                        <div id="step-1">
                            <h2 class="StepTitle">Informations personnelles</h2>
                            <div class="accordion">    
                                <h3>Identité</h3>
                                <div>
                                    <table>
                                        <tr>
                                            <td>{{ form_errors(form.matricule)}}
                                                {{ form_label(form.matricule,'Matricule'|trans)}}</td>
                                                <td>{{ form_widget(form.matricule)}}
                                                    <br>
                                                    <span id="msg_matricule"></span></td>
                                                <td>{{ form_errors(form.nom)}}
                                                {{ form_label(form.nom,'Nom'|trans)}}</td>
                                                    <td>{{ form_widget(form.nom)}}</td>
                                                </tr>
                                                <tr>
                                                    <td>{{ form_errors(form.prenom)}}
                                                {{ form_label(form.prenom,'Prenom'|trans)}}</td>
                                                        <td>{{ form_widget(form.prenom)}}</td>
                                                        <td>{{ form_errors(form.sexe)}}
                                                {{ form_label(form.sexe,'Sexe'|trans)}}</td>
                                                            <td>{{ form_widget(form.sexe)}}</td>    
                                                        </tr>

                                                        <tr>
                                                            <td>{{ form_errors(form.username)}}
                                                {{ form_label(form.username,'Username'|trans)}}</td>
                                                                <td>{{ form_widget(form.username)}}</td>
                                                                <td>{{ form_errors(form.email)}}
                                                {{ form_label(form.email,'E-mail'|trans)}}</td>
                                                                    <td>{{ form_widget(form.email)}}</td>    
                                                                </tr>
                                                                <tr>
                                                                    <td>{{ form_errors(form.date_naissance)}}
                                                {{ form_label(form.date_naissance,'Date de naissance'|trans)}}</td>
                                                                        <td>{{ form_widget(form.date_naissance)}}</td>
                                                                        <td>{{ form_errors(form.photo)}}
                                                {{ form_label(form.photo,'Photo'|trans)}}</td>
                                                                            <td>{{ form_widget(form.photo)}}</td> 

                                                                        </tr>
                                                                        <tr>
                                                                            <td>{{ form_errors(form.num_securite_sociale)}}
                                                {{ form_label(form.num_securite_sociale,'Numéro de securité sociale'|trans)}}</td>
                                                                                <td>{{ form_widget(form.num_securite_sociale)}}</td>
                                                                                <td>{{ form_errors(form.num_carte_identite)}}
                                                {{ form_label(form.num_carte_identite,"Numéro carte d'identité"|trans)}}</td>
                                                                                    <td>{{ form_widget(form.num_carte_identite)}}</td>

                                                                                </tr>
                                                                                <tr>
                                                                                    <td>{{ form_errors(form.date_delivrance)}}
                                                {{ form_label(form.date_delivrance,'Date delivrance'|trans)}}</td>
                                                                                        <td>{{ form_widget(form.date_delivrance)}}</td>
                                                                                        <td>{{ form_errors(form.nationalite)}}
                                                {{ form_label(form.nationalite,"Nationalité"|trans)}}</td>
                                                                                            <td>{{ form_widget(form.nationalite)}}</td>

                                                                                        </tr>
                                                                                    </table>


                                                                                </div>
                                                                                <h3>Adresse</h3>

                                                                                <div>
                                    {{ form_widget(form.adresses)}}
                                                                                        <table>

                                                                                        </table>  
                                                                                    </div>
                                                                                    <h3>Situation familiale</h3>
                                                                                    <div>

                                                                                    </div>
                                                                                    <h3>Coordonnées personnelles</h3>
                                                                                    <div>
                                                                                        <table>
                                                                                            <tr>
                                                                                                <td>{{ form_errors(form.telephoneDomicile)}}
                                                {{ form_label(form.telephoneDomicile,'Téléphone domicile:'|trans)}}</td>
                                                                                                    <td>{{ form_widget(form.telephoneDomicile)}}</td>

                                                                                                    <td>{{ form_errors(form.mobile1Perso)}}
                                                {{ form_label(form.mobile1Perso,'Mobile personnel 1:'|trans)}}</td>
                                                                                                        <td>{{ form_widget(form.mobile1Perso)}}</td>    
                                                                                                    </tr>

                                                                                                    <tr>
                                                                                                        <td>{{ form_errors(form.mobile2Perso)}}
                                                {{ form_label(form.mobile2Perso,'Mobile personnel 2:'|trans)}}</td>
                                                                                                            <td>{{ form_widget(form.mobile2Perso)}}</td>
                                                                                                            <td>{{ form_errors(form.mobile3Perso)}}
                                                {{ form_label(form.mobile3Perso,'Mobile personnel 3:'|trans)}}</td>
                                                                                                                <td>{{ form_widget(form.mobile3Perso)}}</td>
                                                                                                            </tr>
                                                                                                            <tr>
                                                                                                                <td>{{ form_errors(form.telephoneTravail)}}
                                                {{ form_label(form.telephoneTravail,'Téléphone travail:'|trans)}}</td>
                                                                                                                    <td>{{ form_widget(form.telephoneTravail)}}</td>
                                                                                                                    <td>{{ form_errors(form.mobile1Pro)}}
                                                {{ form_label(form.mobile1Pro,'Mobile professionel 1:'|trans)}}</td>
                                                                                                                        <td>{{ form_widget(form.mobile1Pro)}}</td>
                                                                                                                    </tr>
                                                                                                                    <tr>
                                                                                                                        <td>{{ form_errors(form.mobile2Pro)}}
                                                {{ form_label(form.mobile2Pro,'Mobile professionel 2:'|trans)}}</td>
                                                                                                                            <td>{{ form_widget(form.mobile2Pro)}}</td>
                                                                                                                            <td>{{ form_errors(form.mobile3Pro)}}
                                                {{ form_label(form.mobile3Pro,'Mobile professionel 3:'|trans)}}</td>
                                                                                                                                <td>{{ form_widget(form.mobile3Pro)}}</td>
                                                                                                                            </tr>
                                                                                                                            <tr>
                                                                                                                                <td>{{ form_errors(form.emailPro)}}
                                                {{ form_label(form.emailPro,'E-mail professionel:'|trans)}}</td>
                                                                                                                                    <td>{{ form_widget(form.emailPro)}}</td>
                                                                                                                                    <td>{{ form_errors(form.emailPerso)}}
                                                {{ form_label(form.emailPerso,'E-mail personnel:'|trans)}}</td>
                                                                                                                                        <td>{{ form_widget(form.emailPerso)}}</td>
                                                                                                                                    </tr>
                                                                                                                                </table> 
                                                                                                                            </div>
                                                                                                                            <h3>Etat physique</h3>
                                                                                                                            <div>

                                                                                                                            </div>
                                                                                                                        </div>

                                                                                                                    </div>               
                                                                                                                    <div id="step-2">
                                                                                                                        <h2 class="StepTitle">Informations Professionelles</h2>
                                                                                                                    </div>
                                                                                                                    <div id="step-3">
                                                                                                                        <h2 class="StepTitle">Rémunération Théorique</h2>
                                                                                                                    </div>


                                                                                                                </div>
                                                                                                                <!-- End SmartWizard Content -->  		
                                                                                                            </form> 


            {% block sonata_post_fieldsets %}{% endblock %}

            {{ form_rest(form) }}

            {% block formactions %}
                                                                                                                   
            {% endblock formactions %}
                                                                                                                </form>
                                                                                                                </fieldset> 
                                                                                                            </div>
    {% endif%}
                                                                                                            <script>
                                                                                                                $('.buttonFinish').click(function(){
                                                                                                                    alert('ok')
                                                                                                                $('#form_user').submit()
                                                                                                            })
                                                                                                            $( ".accordion" ).accordion();
                                                                                                                </script>
{% endblock %}